package com.xsj.controller;



import com.xsj.dto.ResponseDto;
import com.xsj.mapper.AdressMapper;
import com.xsj.service.AdressService;
import com.xsj.utils.AMapGeocoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: fore-phases
 * @BelongsPackage: com.ksj.controller
 * @Author: 康思捷
 * @CreateTime: 2025-06-09 11:44
 * @Description: 用户地址管理
 * @Version: 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/adress")
public class AdressController {
    @Autowired
    AMapGeocoder aMapGeocoder;
    @Autowired
    AdressService adressService;

    @GetMapping("/useradressint")
    public ResponseDto useradressint(@RequestParam("address")  String address,@RequestParam("userId")int userId
            ,@RequestParam("client")String client,@RequestParam("clientPhone")String clientPhone
            ,@RequestParam("clientSex")int clientSex){
        double[] test = aMapGeocoder.test(address);
        if (adressService.InitAdress(userId,test[0],test[1],address,client,clientPhone,clientSex)!=null){
        return ResponseDto.success("新增成功");
        }else {
            return ResponseDto.err(10005,"新增失败");
        }
    }
    @GetMapping("/useradressup")
    public ResponseDto useradressup(@RequestParam("address")  String address,@RequestParam("addressId")int addressId
            ,@RequestParam("client")String client,@RequestParam("clientPhone")String clientPhone
            ,@RequestParam("clientSex")int clientSex){
        if (address!=null){
            double[] test = aMapGeocoder.test(address);
            if (adressService.UPAdress(addressId,test[0],test[1],address,client,clientPhone,clientSex)!=null){
                return ResponseDto.success("修改成功");
            }else {
                return ResponseDto.err(10005,"修改失败");
            }
        }else {
            if (adressService.UPAdress(addressId,0,0,address,client,clientPhone,clientSex)!=null){
                return ResponseDto.success("修改成功");
            }else {
                return ResponseDto.err(10005,"修改失败");
            }
        }
    }
    @GetMapping("/useradressde")
    public ResponseDto useradressde(@RequestParam("addressId")int addressId){
        if (adressService.DeAderss(addressId)!=null){
            return ResponseDto.success("修改成功");
        }
        return ResponseDto.err(10005,"删除失败");
    }
    @GetMapping("/useradressse")
    public ResponseDto useradressse(@RequestParam("userId")int userId){
        ResponseDto responseDto = adressService.SeAdress(userId);
        return responseDto;
    }

//    @GetMapping("/merchantadress")
//    public ResponseDto merchantadress(@RequestParam("address")  String address,@RequestParam("id")  int id){
//        double[] test = aMapGeocoder.test(address);
//        adressMapper.UPAdress(id,test[0],test[1],address);
//        return ResponseDto.success("成功");
//    }

}
